import { reactive } from 'vue'
import {BalanceApi} from '@@/api/api.js'
import {useRouter} from 'vue-router'

function useWithdrawLimit(channelInfo){
    console.log('limit',channelInfo);
    const router = useRouter()
    const state = reactive({
        isNewWithdraw:false,
        isVip:false,
        canWithdraw:false,
        canRecharge:false,
    })
    const failureModalData = reactive({
        show:false,
    })
    const vipModalData = reactive({
        show:false,
        showModal:()=>{
            vipModalData.show = true
        },
        submit:()=>{
            window.trackEvent({pageTitle: 'withdrawpage',ev:'clickGoToButton'})
            router.push({name:'member'})
        }
    })
    async function getLimitInfo(){
        const {newWithdraw,equity,withdraw,prepaidRecharge} = await BalanceApi.WithdrawLimit()
        state.isNewWithdraw = newWithdraw
        state.isVip = equity
        state.canWithdraw = withdraw
        state.canRecharge = prepaidRecharge
        // console.log('testLimit',state,withdrawOptionsModalData);
        // switchWithdraw()
    }
    function switchWithdraw(today = true){
        if(state.isNewWithdraw && !state.canWithdraw && !state.isVip){
            vipModalData.showModal()
            window.trackEvent({pageTitle: 'withdrawpage',ev:'showMemberPop'})
            return false
        }else if(!today){
            failureModalData.show = true
            return false
        }else{
            return true
        }
    }
    return {
        state,
        vipModalData,
        getLimitInfo,
        switchWithdraw,
        failureModalData
    }
}
export {useWithdrawLimit}